<%namespace name="tw" module="tw.core.mako_util"/>\
<%
    attrs = context.get('attrs')
    error = context.get('error')
%>\
<div ${ tw.attrs(
    [('id', context.get('id')+".container")]
) }>
% if error and show_error:
<div class="fielderror">${tw.content(error)}</div>
% endif
<select ${tw.attrs(
    [('id', context.get('id')+".select"),
     ('class', css_class)],
    attrs=attrs
)}>
    % for group, options in grouped_options:
    % if group:
    <optgroup ${tw.attrs([('label', group)])}>
    % endif
        % for value, desc, attrs in options:
        <option ${tw.attrs(
            [('value', value)],
            attrs=attrs
        )}>${tw.content(desc)}</option>
        % endfor
    % if group:
    </optgroup>
    % endif
    % endfor
</select>\
<br />
<textarea ${ tw.attrs(
    [('id', context.get('id')),
     ('name', name),
     ('style', "display:none")]
) }>${ context.get('value')|h }</textarea>
<span ${ tw.attrs(
    [('id', context.get('id')+".preview")]
) }></span>
</div>
